package com.mjlf.robot.hook;

import lc.kra.system.keyboard.GlobalKeyboardHook;
import lc.kra.system.keyboard.event.GlobalKeyAdapter;
import lc.kra.system.keyboard.event.GlobalKeyEvent;
import lc.kra.system.mouse.GlobalMouseHook;
import lc.kra.system.mouse.event.GlobalMouseAdapter;
import lc.kra.system.mouse.event.GlobalMouseEvent;

import java.util.Map;

/**
 * @ClassName Test
 * @Author mjlft
 * @Date 2020/3/7 9:57
 * @Version 1.0
 * @Description TODO
 */
public class Test {
    private static boolean run = true;

    public static void main(String[] args) {
        GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(true);
        GlobalMouseHook mouseHook = new GlobalMouseHook(true);

//        for (Map.Entry<Long, String> keyboard : GlobalKeyboardHook.listKeyboards().entrySet()){
//            System.out.println(keyboard.getKey().intValue());

        keyboardHook.addKeyListener(new GlobalKeyAdapter() {
            @Override
            public void keyPressed(GlobalKeyEvent event) {
                System.out.println(event);
                if (event.getVirtualKeyCode() == GlobalKeyEvent.VK_ESCAPE)
                    run = false;
            }

            @Override
            public void keyReleased(GlobalKeyEvent event) {
                System.out.println(event);
            }
        });
        mouseHook.addMouseListener(new GlobalMouseAdapter(){
            @Override
            public void mousePressed(GlobalMouseEvent event) {
                System.out.println(event.getX());
                System.out.println(event.getButton());
            }

            @Override
            public void mouseReleased(GlobalMouseEvent event) {
                super.mouseReleased(event);
            }

            @Override
            public void mouseMoved(GlobalMouseEvent event) {
                super.mouseMoved(event);
            }

            @Override
            public void mouseWheel(GlobalMouseEvent event) {
                super.mouseWheel(event);
            }
        });
//    }
        try {
            while (run) Thread.sleep(128);
        } catch (InterruptedException e) { /* nothing to do here */ } finally {
            keyboardHook.shutdownHook();
        }
    }
}
